﻿//======================================================
//==     (c)2008 aspxcms inc by NeTCMS v1.0              ==
//==          Forum:bbs.aspxcms.com                   ==
//==         Website:www.aspxcms.com                  ==
//======================================================
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using NetCMS.Content;
using NetCMS.Content.Common;
using NetCMS.Model;

public partial class manage_survey_setItem : NetCMS.Web.UI.ManagePage
{
    Survey sur = new Survey();
    rootPublic rd = new rootPublic();
    protected void Page_Load(object sender, EventArgs e)
    {
        this.PageNavigator1.OnPageChange += new PageChangeHandler(PageNavigator1_PageChange);
        if (!IsPostBack) //判断页面是否重载
        {
            //判断用户是否登录
            copyright.InnerHtml = CopyRight;//获取版权信息
            if (SiteID == "0")
            {
                param_id.InnerHtml = "<a href=\"setParam.aspx\" class=\"list_link\">系统参数设置</a>&nbsp;┊&nbsp;";
            }
            if (Request.QueryString["type"] == "delone")
                setItemDel();

            VoteItemManage(1);  //初始分页数据

        }
    }
    /// <summary>
    /// 分页
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="PageIndex"></param>
    /// code by chenzhaohui

    protected void PageNavigator1_PageChange(object sender, int PageIndex)
    {
        VoteItemManage(PageIndex);//管理页面分页查询
    }

    /// <summary>
    /// 删除单个事件
    /// </summary>
    ///code by chenzhaohui 

    void setItemDel()
    {
        int IID = int.Parse(Request.QueryString["ID"]);
        if (IID <= 0)
        {
            PageError("错误的参数传递!", "");
        }
        else
        {
            if (sur.Del_voteManage(IID, 2) == 0)
            {
                PageError("意外错误：未知错误", "");
            }
            else
            {
                rd.SaveUserAdminLogs(1, 1, UserNum, "删除投票选项", "删除成功");
                PageRight("删除成功。", "VoteItem.aspx");
            }
        }
    }

    /// <summary>
    /// 管理列表页
    /// </summary>
    /// <param name="PageIndex"></param>
    /// code by chenzhaohui

    protected void VoteItemManage(int PageIndex)//显示投票选项管理页面
    {
        #region 查询条件判断语句

        string KeyWord = this.KeyWord.Text.Trim();//关键字
        string type = this.DdlKwdType.SelectedValue;//选择类型
        int i = 0, j = 0;
        int num = PAGESIZE;//从参数设置里取得每页显示记录的条数
        DataTable dt = null;
        if (KeyWord != "" && KeyWord != null)//如果关键字不为空，则执行下面的条件语句
        {
            switch (type)
            {
                case "choose":
                    break;
                case "title":
                    DataTable dt1 = new DataTable();
                    dt1 = sur.sel_voteByStr(KeyWord, 0);
                    if (dt1 != null)
                    {
                        if (dt1.Rows.Count > 0)
                        {
                            for (int l = 0; l < dt1.Rows.Count; l++)
                            {
                                int tid = int.Parse(dt1.Rows[l]["TID"].ToString());
                                SQLConditionInfo st = new SQLConditionInfo("@TID", "%" + tid + "%");
                                dt = NetCMS.Content.Pagination.GetPage("manage_survey_VoteItem_1_aspx", PageIndex, num, out i, out j, st);
                            }
                        }
                        else
                        {
                            dt = NetCMS.Content.Pagination.GetPage("manage_survey_VoteItem_2_aspx", PageIndex, num, out i, out j, null);
                        }
                    }
                    else
                    {
                        dt = NetCMS.Content.Pagination.GetPage("manage_survey_VoteItem_2_aspx", PageIndex, num, out i, out j, null);
                    }
                    break;
                case "ItemNamee":
                    SQLConditionInfo st1 = new SQLConditionInfo("@ItemName", "%" + KeyWord + "%");
                    dt = NetCMS.Content.Pagination.GetPage("manage_survey_VoteItem_3_aspx", PageIndex, num, out i, out j, st1);
                    break;
                case "PicSrcc":
                    SQLConditionInfo st3 = new SQLConditionInfo("@PicSrc", "%" + KeyWord + "%");
                    dt = NetCMS.Content.Pagination.GetPage("manage_survey_VoteItem_4_aspx", PageIndex, num, out i, out j, st3);
                    break;
                case "DisColorr":
                    SQLConditionInfo st4 = new SQLConditionInfo("@DisColor", "%" + KeyWord + "%");
                    dt = NetCMS.Content.Pagination.GetPage("manage_survey_VoteItem_5_aspx", PageIndex, num, out i, out j, st4);
                    break;
                case "VoteCountt":
                    SQLConditionInfo st5 = new SQLConditionInfo("@VoteCount", "%" + KeyWord + "%");
                    dt = NetCMS.Content.Pagination.GetPage("manage_survey_VoteItem_6_aspx", PageIndex, num, out i, out j, st5);
                    break;
                case "ItemDetaill":
                    SQLConditionInfo st6 = new SQLConditionInfo("@ItemDetail", "%" + KeyWord + "%");
                    dt = NetCMS.Content.Pagination.GetPage("manage_survey_VoteItem_7_aspx", PageIndex, num, out i, out j, st6);
                    break;
            }
        }
        else
        {
            dt = NetCMS.Content.Pagination.GetPage("manage_survey_VoteItem_2_aspx", PageIndex, num, out i, out j, null);
        }
        #endregion
        this.PageNavigator1.PageCount = j;
        this.PageNavigator1.PageIndex = PageIndex;
        this.PageNavigator1.RecordCount = i;
        /*
        dt.Columns.Add("ItemModel", typeof(String));//选项模式
        dt.Columns.Add("oPerate", typeof(String));//操作
        dt.Columns.Add("title", typeof(String));
        for (int k = 0; k < dt.Rows.Count; k++)
        {
            int idt = int.Parse(dt.Rows[k]["tid"].ToString());
            int idi = int.Parse(dt.Rows[k]["iid"].ToString());
            int ItemModee = int.Parse(dt.Rows[k]["ItemMode"].ToString());//选项模式
            try
            {
                //从主题表中取主题名
                string VoteTitleName = sur.GetVoteTitle(idt);//取得主题的值

                dt.Rows[k]["title"] = VoteTitleName;//将查找出来的值传给调查主题栏
            }
            catch { }
            switch (ItemModee)
            {
                case 1:
                    dt.Rows[k]["ItemModel"] = "文字描述模式";
                    break;
                case 2:
                    dt.Rows[k]["ItemModel"] = "自主填写模式";
                    break;
                case 3:
                    dt.Rows[k]["ItemModel"] = "图片模式";
                    break;
                default:
                    dt.Rows[k]["ItemModel"] = "文字描述模式";
                    break;
            }
            dt.Rows[k]["ItemName"] = "<a href='Item_Add.aspx?&iid=" + idi + "' class='list_link'>" + dt.Rows[k]["ItemName"].ToString() + "</a>";
            dt.Rows[k]["oPerate"] = "<a href=\"Item_Add.aspx?&iid=" + idi + "\"  class=\"list_link\" title=\"修改此项\"><img src=\"../../sysImages/" + NetCMS.Config.UIConfig.CssPath() + "/sysico/edit.gif\" border=\"0\" alt=\"修改此项\" /></a><a href=\"VoteItem.aspx?type=delone&id=" + idi + "\"  class=\"list_link\" title=\"删除此项\" onclick=\"{if(confirm('确认删除吗？')){return true;}return false;}\"><img src=\"../../sysImages/" + NetCMS.Config.UIConfig.CssPath() + "/sysico/del.gif\" border=\"0\" alt=\"删除此项\" /></a><input type='checkbox' name='vote_checkbox' id='vote_checkbox' value=\"" + idi + "\"/>";
        }
        */
        DataList1.DataSource = dt;
        DataList1.DataBind();
    }
    //查询操作
    protected void BtnSearch_Click(object sender, EventArgs e)
    {
        VoteItemManage(1);
    }



    /// <summary>
    /// 批量删除
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    /// code by chenzhaohui

    protected void DelP_Click(object sender, EventArgs e)
    {
        string vote_checkbox = Request.Form["vote_checkbox"];
        if (vote_checkbox == null || vote_checkbox == String.Empty)
        {
            PageError("请先选择批量操作的内容!", "");
        }
        else
        {
            String[] CheckboxArray = vote_checkbox.Split(',');
            vote_checkbox = null;
            for (int i = 0; i < CheckboxArray.Length; i++)
            {
                if (sur.del_voteSql(CheckboxArray[i], 6) == 0)
                {
                    PageError("删除数据失败,请与管理联系!", "");
                    break;
                }
            }
            rd.SaveUserAdminLogs(1, 1, UserNum, "问卷调查系统批量删除选项", "删除数据成功");
            PageRight("删除数据成功,请返回继续操作!", "VoteItem.aspx");
        }
    }


    /// <summary>
    /// 删除全部
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    ///code by chenzhaohui

    protected void DelAll_Click(object sender, EventArgs e)
    {
        if (sur.del_VoteInfo(2) == false)
        {
            PageError("意外错误：未知错误", "");
        }
        else
        {
            rd.SaveUserAdminLogs(1, 1, UserNum, "问卷调查系统删除选项", "删除数据成功");
            PageRight("删除全部成功。", "VoteItem.aspx");
        }
    }
    static protected string GetMode(object input)
    {
        if (input == null || input == DBNull.Value)
            return string.Empty;
        try
        {
            int n = Convert.ToInt32(input);
            switch (n)
            {
                case 1:
                    return "文字描述模式";
                case 2:
                    return "图片模式";
                default:
                    return "文字描述模式";
            }
        }
        catch
        {
            return string.Empty;
        }
    }
}
